<?php
require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'wsr.inc.php';
require_once WSR_DIR . 'activation.class.php';
require_once MORIARTY_DIR . "simplegraph.class.php";
require_once MORIARTY_ARC_DIR . 'ARC2.php';
//require_once MORIARTY_ARC_DIR . 'serializers' . DIRECTORY_SEPARATOR . 'ARC2_TurtleSerializer.php';

class ActivaionTest extends PHPUnit_Framework_TestCase {
	
	function test_sigmoid() {
		$data = array( array(-1,0), array(0,0), array(0.34008,0.068016), array(1,0.2), array(2,0.4), array(10,2), 
                       array(34.008,18.012), array(42.012,31.6276), array(100,100), array(102.1204,100) );
		$delta = 0.1;
		$activation = new ActivationParams();
		foreach( $data as $datum ) {
			list($x,$sig_expected) = $datum;
			$sig = $activation->sigmoid($x);
			$this->assertEquals( $sig, $sig_expected, "result of sigmoid($x)", $delta );
		}

	}

	function test_inverse_sigmoid() {
		$data = array( array(0,0), array(0.34008,0.068016), array(1,0.2), array(2,0.4), array(10,2), 
                       array(34.008,18.012), array(42.012,31.6276), array(100,100) );
		$delta = 0.1;
		$activation = new ActivationParams();
		foreach( $data as $datum ) {
			list($isig_expected,$y) = $datum;
			$isig = $activation->inverse_sigmoid($y);
			$this->assertEquals( $isig, $isig_expected, "result of inverse_sigmoid($y)", $delta );
		}

	}

	function test_inverse_sigmoid_vs_sigmoid() {
		$delta = 0.1;
		$activation = new ActivationParams();
		$data = array( 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 );
		foreach( $data as $datum ) {
			list($x,$sig_expected) = $datum;
			$x = $activation->inverse_sigmoid($datum);
			$sig = $activation->sigmoid($x);
			$this->assertEquals( $sig, $datum, "inverse_sigmoid normal range", $delta );
		}
		// also check extremes
		$isig_lo = $activation->inverse_sigmoid(-5);
		$this->assertEquals( $isig_lo, 0, "inverse_sigmoid below range", $delta );
		$isig_hi = $activation->inverse_sigmoid(105);
		$this->assertEquals( $isig_hi, 100, "inverse_sigmoid abive range", $delta );

	}

}


?>